package com.yucc.girlimage.io.upyun;

import java.util.Date;

import android.os.Parcel;
import android.os.Parcelable;

public class FolderItem implements Parcelable {
	public String name; // / 文件名
	public String type; // / 文件类型 {file, folder}
	public long size; // / 文件大小
	public Date date; // / 文件日期
	public String path ;
	public boolean haveFaved ;

	public FolderItem() {
		super();
	}

	public FolderItem(String data, String path) {
		String[] a = data.split("\t");
		if (a.length == 4) {
			this.name = a[0];
			this.type = (a[1].equals("N") ? "File" : "Folder");
			try {
				this.size = Long.parseLong(a[2].trim());
			} catch (NumberFormatException e) {
				this.size = -1;
			}
			long da = 0;
			try {
				da = Long.parseLong(a[3].trim());
			} catch (NumberFormatException e) {
			}
			this.date = new Date(da * 1000);
		}
		this.path = path ;
	}
	
	@Override
	public String toString() {
		return path + "/" + name;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((path == null) ? 0 : path.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		FolderItem other = (FolderItem) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (path == null) {
			if (other.path != null)
				return false;
		} else if (!path.equals(other.path))
			return false;
		return true;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(name);
		dest.writeString(type);
		dest.writeLong(size);
		dest.writeLong(date.getTime());
		dest.writeString(path);
		if(haveFaved) dest.writeInt(1) ;
		else dest.writeInt(0) ;
	}
	
	public static final Parcelable.Creator<FolderItem> CREATOR = new Parcelable.Creator<FolderItem>() {
		// 重写Creator

		public FolderItem createFromParcel(Parcel source) {
			FolderItem item = new FolderItem() ;
			item.name = source.readString() ;
			item.type = source.readString() ;
			item.size = source.readLong() ;
			item.date = new Date(source.readLong()) ;
			item.path = source.readString() ;
			item.haveFaved = source.readInt() == 1 ? true :false ;
			return item ;
		}
		public FolderItem[] newArray(int size) {
			// TODO Auto-generated method stub
			return null;
		}
	} ;
}